package com.kuang.springcloud.Controller;

import com.kuang.springcloud.Service.IUserService;
import com.kuang.springcloud.pojo.User;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Resource
    IUserService userService;


    @GetMapping("/user/getOne/{id}")
//    @HystrixCommand(fallbackMethod = "hystrixGet")
    @CircuitBreaker(name = "backendB",fallbackMethod = "hystrixGet")
    public User selectOne(@PathVariable("id") Integer id){

        User user= userService.selectOne(id);
//        if (user==null){
//            throw  new RuntimeException("id=>"+id+"无数据");
//        }
        return user;
    }
    public User hystrixGet(Integer id ,Exception e){
        return new User().setUserNo(id)
                .setUserName("查无此人，进入服务熔断，此信息由hystrix返回")
                .setDbSource("无数据");
    }
}
